package com.dianwoba.core.spring;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.web.servlet.DispatcherServlet;

import com.dianwoba.utils.StaticResourceUtil;

/**
 * 重写Spring DispatcherServlet初始化方法，取到context
 * @author licf
 */
@SuppressWarnings("serial")
public class DianwobaDispatcherServlet extends DispatcherServlet {

	@Override
	public void init(ServletConfig config) throws ServletException {
		// 加载Spring
		super.init(config);
		
		final ServletContext sc = config.getServletContext();
		
		// 获取Spring的ApplicationContext并赋值给ContextHolder
		ContextHolder.setCtx(getWebApplicationContext());
		
		final String contextPath = sc.getContextPath();
		final String webRootAbsolutePath = sc.getRealPath("");
		StaticResourceUtil.initialize(contextPath, webRootAbsolutePath);
	}

}
